<?php
  class Plugins_Imagewidth extends model {
  
  
  
  function getformadd($productid="")
  {
  
  
  
  
  $echo=1;
  $textlabel='Image';
if(NameDmconnex=='Canonlife')
{
$textlabel='ภาพถ่าย';

}

$str='    <div class="wrpPlg clBg5 clBd2 bdFull image1">
                    <div class="plgArea"></div>
                    <div class="wrpOutAtcPlg">
                        <div class="wrpAtcPlg">
                            <span class="ico icoImgPlg"></span>
                            <div class="spnAtcPlg clTxtW">
                                <span class="fs03">'.$textlabel.'</span><br>
                                <span class="rcmSizeAdd fs01">recommended size width: 640px</span>
                            </div>
                        </div>
                    </div>
                    <div class="wrpTl">
                        <div class="btnIco closeTl clBd3 mgBtm10 deleterowbutton" title="Close">
                            <span class="ico icoCloseTl"></span>
                        </div>
                        <div class="addTool">
                            <div class="btnIco addImgTl clBd3 bdBtm uploadbutton" title="Browse">
                                <span class="ico icoAddImgTl"></span>
                                <div class="wrpUlFile" >
                                    
                                </div>
                            </div>
                            <div class="btnIco addCldTl clBd3 bdBtm cloudbutton" title="Cloud">
                                <span class="ico icoAddCldTl"></span>
                            </div>
                            <div class="btnIco addLnkTl clBd3 bdBtm linkbutton" title="Link">
                                <span class="ico icoAddLnkTl"></span>
                            </div>
                            <div class="btnIco btnRmvTl deletebutton" title="Remove">
                                <span class="ico icoRmvTl"></span>
                            </div>
                        </div>
                    </div>
                    <span class="desPlg clTxt3 fs03">Select an image recommend size 640 x 360 px</span>
                    <form class="frmTprPlg" onsubmit="return false;">
                       
                    
                        <input name="detail[]" type="text" class="inpAddCtntNoBd inpTprPlg w616 clTxt2 fs03" placeholder="Type text here to explain this image.">
                        </form>
                 
                </div>';
  
  
  
  $arraydata['form']=addslashes(str_replace(array("\r", "", "\r"), '', $str));
 // $arraydata['js'][]=pluginjsinfo.'/image.js';
  //$arraydata['js'][]=baseinfo.'/js/jquery.Jcrop.min.js';
 // $arraydata['js'][]=baseinfo.'/js/jquery.iuploader-1.0.js';
  
  
      
  
  
  
  return $arraydata;
  
  
  
  
  
  
  
  }
  
  function getformlanding($arraydata)
  {
  
 if($arraydata['simg']['newpath'])
 {
$code  = '<div class="ldIt wrpImgLd clBg4 w640" onclick="openmaingallery('.$arraydata['simgmid'].')">'."";

$code .= '<div class="icoDefLd">'."";
$code .= '<span class="ico icoImgDefLd"></span>'."";
$code .= '<span></span>'."";
$code .= '</div>'."";

$code .= '<div class="wrpImgDesLd">'."";

$code .= '<a href="javascript:void(0)"   class="galleryimage"><img  id="img-'.$arraydata['simgmid'].'" title="'.$arraydata['img']['newpath'].'" width="640"   alt="'.$arraydata['img']['width'].'|'.$arraydata['img']['height'].'" src="'.$arraydata['simg']['newpath'].'"></a>'."";
$codeset="";
if($arraydata['detail']=="")
{
$codeset='style="display:none"';
}
$code .= '<div class="desImgLd clTxtW" '.$codeset.'>'."";

$code .= '<div  class="ovlLd ovlImgLd w640">'."";
$code .= '<p class="cutTxt">'.$arraydata['detail'].'</p>'."";
$code .= '</div>'."";

$code .= '</div>'."";

$code .= '</div>'."";

$code .= '</div>';
 }
 
 if(count($arraydata['other'])&&is_array($arraydata['other']))
 {
 $model='';
 if($arraydata['other']['IFD0']['Model'])
 {
 $model=$arraydata['other']['IFD0']['Model'];
 
 }
 
 
  $len='';
 if($arraydata['other']['EXIF'])
 {
 if($arraydata['other']['EXIF']['UndefinedTag:0xA434'])
 {
 $len=$arraydata['other']['EXIF']['UndefinedTag:0xA434'];
 }
 
 }
 
 
   $focus='';
 if($arraydata['other']['EXIF'])
 {
 if($arraydata['other']['EXIF']['FocalLength'])
 {
 $focus=$arraydata['other']['EXIF']['FocalLength'];
 }
 
 }
 
 
 
 $shutter='';
 if($arraydata['other']['EXIF'])
 {
 if($arraydata['other']['EXIF']['ISOSpeedRatings'])
 {
 $shutter=$arraydata['other']['EXIF']['ISOSpeedRatings'];
 }
 }
 
 $aperture='';
  if($arraydata['other']['COMPUTED'])
 {
 if($arraydata['other']['COMPUTED']['ApertureFNumber'])
 {
 $aperture=$arraydata['other']['COMPUTED']['ApertureFNumber'];
 }
 }
 
 
  $exposure='';
  if($arraydata['other']['EXIF'])
 {
 if($arraydata['other']['EXIF']['ExposureTime'])
 {
 $exposure=$arraydata['other']['EXIF']['ExposureTime'];
 }
 }
 
 
   $createdate='';
  if($arraydata['other']['IFD0'])
 {
 if($arraydata['other']['IFD0']['DateTime'])
 {
 $createdate=$arraydata['other']['IFD0']['DateTime'];
 }
 }
 
 
 
 $artist='';
  if($arraydata['other']['IFD0'])
 {
 if($arraydata['other']['IFD0']['Artist'])
 {
 $artist=$arraydata['other']['IFD0']['Artist'];
 }
 }
 
//
//  echo "<pre>";
// print_r($arraydata);
// echo "</pre>;";
// exit;
 
$code .= '<div class="ldIt wrpNewExifData">'."\n";
$code .= '<ul class="clearfix">'."\n";
if($model)
{
$link=$model;

$code .= '<li class="wrpOutNewExifData" onclick="linkto(\''.baseinfo.'/exifdata/Model/'.$link.'\')">'."\n";
$code .= '<div class="newExifData clearfix modlExif">'."\n";
$code .= '<span class="ico4 icoModlExif"></span>'."\n";
$code .= '<span class="spnNewExif">'.$model.'</span>'."\n";
$code .= '</div>'."\n";
$code .= '<div class="wrpPopExif wrpPopModlExif">'."\n";
$code .= '<div class="wrpInPopExif">'."\n";
$code .= '<div class="popExif popModlExif">'."\n";
$code .= '<span>Camera Model</span>'."\n";
$code .= '</div>'."\n";
$code .= '<div class="triExif"></div>'."\n";
$code .= '</div>'."\n";
$code .= '</div>'."\n";
$code .= '</li>'."\n";
}

if($len)
{
$link=str_replace('/','ppset',$len);
$code .= '<li class="wrpOutNewExifData" onclick="linkto(\''.baseinfo.'/exifdata/UndefinedTag:0xA434/'.$link.'\')">'."\n";
$code .= '<div class="newExifData clearfix lensExif">'."\n";
$code .= '<span class="ico4 icoLensExif"></span>'."\n";
$code .= '<span class="spnNewExif">'.$len.'</span>'."\n";
$code .= '</div>'."\n";
$code .= '<div class="wrpPopExif wrpPoplensExif">'."\n";
$code .= '<div class="wrpInPopExif">'."\n";
$code .= '<div class="popExif popLensExif">'."\n";
$code .= '<span>Lens</span>'."\n";
$code .= '</div>'."\n";
$code .= '<div class="triExif"></div>'."\n";
$code .= '</div>'."\n";
$code .= '</div>'."\n";
$code .= '</li>'."\n";
}

if($focus)
{
$link=str_replace('/','-',$focus);
//$focus=eval($focus).'mm';
list($d1,$d2)=explode("/",$focus);
$focus=($d1/$d2).' mm';
$code .= '<li class="wrpOutNewExifData" onclick="linkto(\''.baseinfo.'/exifdata/FocalLength/'.$link.'\')">'."\n";
$code .= '<div class="newExifData clearfix foclExif">'."\n";
$code .= '<span class="ico4 icoFoclExif"></span>'."\n";
$code .= '<span class="spnNewExif">'.$focus.'</span>'."\n";
$code .= '</div>'."\n";
$code .= '<div class="wrpPopExif wrpPopFoclExif">'."\n";
$code .= '<div class="wrpInPopExif">'."\n";
$code .= '<div class="popExif popFoclExif">'."\n";
$code .= '<span>Focal Length</span>'."\n";
$code .= '</div>'."\n";
$code .= '<div class="triExif"></div>'."\n";
$code .= '</div>'."\n";
$code .= '</div>'."\n";
$code .= '</li>'."\n";
}

if($exposure)
{
$link=str_replace('/','-',$exposure);
$code .= '<li class="wrpOutNewExifData" onclick="linkto(\''.baseinfo.'/exifdata/ExposureTime/'.$link.'\')">'."\n";
$code .= '<div class="newExifData clearfix spedExif">'."\n";
$code .= '<span class="ico4 icoSpedExif"></span>'."\n";
$code .= '<span class="spnNewExif">'.$exposure.'</span>'."\n";
$code .= '</div>'."\n";
$code .= '<div class="wrpPopExif wrpPopSpedExif">'."\n";
$code .= '<div class="wrpInPopExif">'."\n";
$code .= '<div class="popExif popSpedExif">'."\n";
$code .= '<span>Exposure Time</span>'."\n";
$code .= '</div>'."\n";
$code .= '<div class="triExif"></div>'."\n";
$code .= '</div>'."\n";
$code .= '</div>'."\n";
$code .= '</li>'."\n";
}

if($aperture)
{
$link=str_replace('/','-',$aperture);
$code .= '<li class="wrpOutNewExifData" onclick="linkto(\''.baseinfo.'/exifdata/ApertureFNumber/'.$link.'\')">'."\n";
$code .= '<div class="newExifData clearfix aptrExif">'."\n";
$code .= '<span class="ico4 icoAptrExif"></span>'."\n";
$code .= '<span class="spnNewExif">'.$aperture.'</span>'."\n";
$code .= '</div>'."\n";
$code .= '<div class="wrpPopExif wrpPopAptrExif">'."\n";
$code .= '<div class="wrpInPopExif">'."\n";
$code .= '<div class="popExif popAptrExif">'."\n";
$code .= '<span>Aperture</span>'."\n";
$code .= '</div>'."\n";
$code .= '<div class="triExif"></div>'."\n";
$code .= '</div>'."\n";
$code .= '</div>'."\n";
$code .= '</li>'."\n";
}

if($shutter)
{
$link=str_replace('/','-',$shutter);
$code .= '<li class="wrpOutNewExifData" onclick="linkto(\''.baseinfo.'/exifdata/ISOSpeedRatings/'.$link.'\')">'."\n";
$code .= '<div class="newExifData clearfix isoExif">'."\n";
$code .= '<span class="ico4 icoIsoExif"></span>'."\n";
$code .= '<span class="spnNewExif">'.$shutter.'</span>'."\n";
$code .= '</div>'."\n";
$code .= '<div class="wrpPopExif wrpPopIsoExif">'."\n";
$code .= '<div class="wrpInPopExif">'."\n";
$code .= '<div class="popExif popIsoExif">'."\n";
$code .= '<span>ISO/Film</span>'."\n";
$code .= '</div>'."\n";
$code .= '<div class="triExif"></div>'."\n";
$code .= '</div>'."\n";
$code .= '</div>'."\n";
$code .= '</li>'."\n";
}

//$code .= '<li class="wrpOutNewExifData">'."\n";
//$code .= '<div class="newExifData clearfix lctExif">'."\n";
//$code .= '<span class="ico4 icoLctExif"></span>'."\n";
//$code .= '<span class="spnNewExif">1231414.12414</span>'."\n";
//$code .= '</div>'."\n";
//$code .= '<div class="wrpPopExif wrpPopLctExif">'."\n";
//$code .= '<div class="wrpInPopExif">'."\n";
//$code .= '<div class="popExif popLctExif">'."\n";
//$code .= '<span>Latitude and Longitude</span>'."\n";
//$code .= '</div>'."\n";
//$code .= '<div class="triExif"></div>'."\n";
//$code .= '</div>'."\n";
//$code .= '</div>'."\n";
//$code .= '</li>'."\n";

if($createdate)
{
list($link,$time)=explode(" ",$createdate);
list($d1,$d2)=explode(" ",$createdate);
list($y,$m,$d)=explode(":",$d1);
$createdate=$d.'/'.$m.'/'.$y;

$code .= '<li class="wrpOutNewExifData" onclick="linkto(\''.baseinfo.'/exifdata/DateTime/'.$link.'\')">'."\n";
$code .= '<div class="newExifData clearfix dateExif">'."\n";
$code .= '<span class="ico4 icoDateExif"></span>'."\n";
$code .= '<span class="spnNewExif">'.$createdate.'</span>'."\n";
$code .= '</div>'."\n";
$code .= '<div class="wrpPopExif wrpPopDateExif">'."\n";
$code .= '<div class="wrpInPopExif">'."\n";
$code .= '<div class="popExif popDateExif">'."\n";
$code .= '<span>Create Date</span>'."\n";
$code .= '</div>'."\n";
$code .= '<div class="triExif"></div>'."\n";
$code .= '</div>'."\n";
$code .= '</div>'."\n";
$code .= '</li>'."\n";
}

if($artist)
{
$link=str_replace('/','-',$artist);
$code .= '<li class="wrpOutNewExifData" onclick="linkto(\''.baseinfo.'/exifdata/Artist/'.$link.'\')">'."\n";
$code .= '<div class="newExifData clearfix artsExif">'."\n";
$code .= '<span class="ico4 icoArtsExif"></span>'."\n";
$code .= '<span class="spnNewExif">'.$artist.'</span>'."\n";
$code .= '</div>'."\n";
$code .= '<div class="wrpPopExif wrpPopArtsExif">'."\n";
$code .= '<div class="wrpInPopExif">'."\n";
$code .= '<div class="popExif popArtsExif">'."\n";
$code .= '<span>Artist</span>'."\n";
$code .= '</div>'."\n";
$code .= '<div class="triExif"></div>'."\n";
$code .= '</div>'."\n";
$code .= '</div>'."\n";
$code .= '</li>'."\n";
}


$code .= '</ul>'."\n";
$code .= '</div>';
 }
$data['str']=$code;
$data['target']='secondtarget';
  
  return $data; 
  
  
  }
  
  function getplugin_bk($plugreid)
  {
  $sql="select * from tb_plugins_imagewidth where plugreid=".$plugreid;
  $arrayplugin=$this->db->db_set_1recordrow($sql);
 
  $arrayplugin['img']= $this->getimagebyimgmid($arrayplugin['imgmid']);
  $arrayplugin['simg']= $this->getimagebyimgmid($arrayplugin['simgmid']);

  
  return $arrayplugin;
  

  
  }
  
  function getplugin($plugreid)
  {
  $sql="select * from tb_plugins_imagewidth where plugreid=".$plugreid;
  $arrayplugin=$this->db->db_set_1recordrow($sql);
 
  $arrayplugin['img']= $this->getimagebyimgmid($arrayplugin['imgmid'],baseinfo.'/img/dfthmblanding.png');
  $user_agent = strtolower ( $_SERVER['HTTP_USER_AGENT'] );
  if ( preg_match ( "/phone|iphone|itouch|ipod|symbian|android|htc_|htc-|palmos|blackberry|opera mini|iemobile|windows ce|nokia|fennec|hiptop|kindle|mot |mot-|webos\/|samsung|sonyericsson|^sie-|nintendo/", $user_agent ) ) {
                        // these are the most common
                        if($arrayplugin['img']['width']<640)
                        {
                        
                        $arrayplugin['simg']=$arrayplugin['img'];
                        }else
                        {
                        
                        $arrayplugin['simg']= $this->getimagebyimgmid($arrayplugin['simgmid'],baseinfo.'/img/dfthmblanding.png');
                        
                        }
                        
                        
                }else
                {
                $arrayplugin['simg']= $this->getimagebyimgmid($arrayplugin['simgmid'],baseinfo.'/img/dfthmblanding.png');
                
                }
  

  
   $arrayplugin3['check']= $this->getimagebyimgmid($arrayplugin['imgmid'],'','','',',other');
   if((NameDmconnex=="Canonlife"||NameDmconnex=='Infostant')&&($arrayplugin3['check']['other']!="false"&&$arrayplugin3['check']['other']&&strpos($arrayplugin3['check']['other'],"Model")!==false)  )
   {
   $arrayplugin['other']=json_decode($arrayplugin3['check']['other']);
   $arrayplugin['other']=object_to_array($arrayplugin['other']);
   
   
   }else
   {
   $arrayplugin['other']=array();
   }
  
  
  
  return $arrayplugin;
  

  
  }
  
  function saveplugin($arraydata,$productid,$plugreid)
  {
  
  
  $arraydata['productid']=$productid;
  $arraydata['plugreid']=$plugreid;
  
  if($arraydata['photomain'])
  {
  $arraydata['imgmid']= $this->savephotobase64($arraydata['photomain']);
  $arraydata['simgmid']=$arraydata['imgmid'];
  unset($arraydata['photomain']);
  
  }
  else if($arraydata['photolink'])
            {
            $arraydata['imgmid']=$this->savephotolink($arraydata['photolink']);
            $arraydata['simgmid']=$this->savephotolink($arraydata['photolink'],640);
            unset($arraydata['photolink']);   
            
            }
 else if($arraydata['photopath'])
            {
            $arraydata['imgmid']=$this->savephotopath($arraydata['photopath']);
            $arraydata['simgmid']=$this->savephotopath($arraydata['photopath'],640);
            unset($arraydata['photopath']);  
            
            }
  
  if($arraydata['simgmid'])$arraydata['simgmid']=$this->swicthpathimage($arraydata['simgmid'],$productid);
  if($arraydata['imgmid'])
  {
  $arraydata['imgmid']=$this->swicthpathimage($arraydata['imgmid'],$productid);
  
  
 if(NameDmconnex=='Canonlife') 
 {
  $sql=' select other,tb_img.imgmid
FROM
tb_img
where other!="" and other!="false" and other like "%Model%" and tb_img.imgmid='.$arraydata['imgmid'];
          $dataimg=$this->db->db_set_1recordrow($sql);
          
          
          
          $otherdata= json_decode($dataimg['other']);
          $arraydata2['other']=object_to_array($otherdata);
  
 if($dataimg['imgmid'])
 {                            
 $model='';
 if($arraydata2['other']['IFD0']['Model'])
 {
 $model=$arraydata2['other']['IFD0']['Model'];
 $this->savetagrelatedata($model,$productid);
 
 }
 
 /*
  $len='';
 if($arraydata2['other']['EXIF'])
 {
 if($arraydata2['other']['EXIF']['UndefinedTag:0xA434'])
 {
 $len=$arraydata2['other']['EXIF']['UndefinedTag:0xA434'];
 $this->savetagrelatedata($len,$productid);
 }
 
 }
 
 
   $focus='';
 if($arraydata2['other']['EXIF'])
 {
 if($arraydata2['other']['EXIF']['FocalLength'])
 {
 $focus=$arraydata2['other']['EXIF']['FocalLength'];
$link=str_replace('/','-',$focus);
//$focus=eval($focus).'mm';
list($d1,$d2)=explode("/",$focus);
$focus=($d1/$d2).' mm';

$this->savetagrelatedata($focus,$productid);
 
 }
 
 }
 
 
 
 $shutter='';
 if($arraydata2['other']['EXIF'])
 {
 if($arraydata2['other']['EXIF']['ISOSpeedRatings'])
 {
 $shutter='ISO'.$arraydata2['other']['EXIF']['ISOSpeedRatings'];
 $this->savetagrelatedata($shutter,$productid);
 }
 }
 
 $aperture='';
  if($arraydata2['other']['COMPUTED'])
 {
 if($arraydata2['other']['COMPUTED']['ApertureFNumber'])
 {
 $aperture=$arraydata2['other']['COMPUTED']['ApertureFNumber'];
 $this->savetagrelatedata($aperture,$productid);
 }
 }
 
 
  $exposure='';
  if($arraydata2['other']['EXIF'])
 {
 if($arraydata2['other']['EXIF']['ExposureTime'])
 {
 $exposure=$arraydata2['other']['EXIF']['ExposureTime'];
  $this->savetagrelatedata($exposure,$productid);
 }
 }
 */
 }
   
 }
  
          

 
  
  
  }
  
  
  
  
  
  
  $this->db->db_set($arraydata,'tb_plugins_imagewidth');
  
  }
  
  
  }
?>
